package com.glorysoft.xztpda.ui.fttrackin

import android.os.Bundle
import com.glorysoft.xztpda.entity.ui.ToastMessageBean
import com.glorysoft.xztpda.BR
import com.glorysoft.xztpda.R
import com.glorysoft.xztpda.base.BaseActivity
import com.glorysoft.xztpda.databinding.ActivityFtTrackInNextBinding
import com.glorysoft.xztpda.entity.LotInfoEntity
import kotlinx.android.synthetic.main.activity_ft_track_in_next.*

/**
 * FileName: FTTrackInNextAcitivty
 * Author: XJH
 * Date: 2022/4/12 18:21
 * Description:
 * History:
 */
class FTTrackInNextActivity :  BaseActivity<FTTrackInBaseViewModel,ActivityFtTrackInNextBinding>(){

    override fun layoutId(): Int {
        return R.layout.activity_ft_track_in_next
    }

    override fun initVariableId(): Int {
        return BR.fTTrackInBaseViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle("FT进站")
        addActivity(this)
        viewModel.lotInfoEntity = intent.getSerializableExtra("LOTINFO") as LotInfoEntity
        val itemEqp = intent.getSerializableExtra("ITEMEQP") as List<String>
        setRightListener("提交"){
            if (viewModel.mLastLotAdapter.data.isNotEmpty() && viewModel.mLastLotAdapter.index == -1){
                viewModel.defUI.toastEvent.value = ToastMessageBean("请选择尾数批",false)
                return@setRightListener
            }
            viewModel.trackIn(itemEqp)
        }

        rvLotList.adapter = viewModel.mLastLotAdapter
    }

    override fun initData() {
        viewModel.getLastLotList()
        viewModel.initMaterialList()

        viewModel.defUI.startActivity.observe(this){
            viewModel.defUI.toastEvent.value = ToastMessageBean("FT进站成功",true)
            finishAllActivity()
        }
    }

}